<?php
namespace apps\tasksmgr\controllers;

use apps\tasksmgr\bizs\TaskMgrBiz;
use helpers\RetHelper;

class TasksController extends \Phalcon\Mvc\Controller
{
    public function indexAction()
    {
        echo __METHOD__, '<br>';
    }



    public function startTaskAction()
    {

        $taskMgrBiz = TaskMgrBiz::getInstance( $this->di );

        if( !$taskMgrBiz->checkAccessValid($this->request ))
        {
            echo RetHelper::jsonEncode( RetHelper::RET_CODE_FAILURE, '只允许本地ip访问' );
            return;
        }


        var_dump( $taskMgrBiz->dispatchTasks( $this->request, $this->dispatcher ));


    }

    /**
     * rest
     * current server status
     */
    public function serverStatusAction()
    {

    }

    /**
     * 向相关task进程发送停止信号
     */
    public function stopTaskAction()
    {

    }

    /**
     * rest
     */
    public function taskStatusAction()
    {
        echo json_encode( $this->di->httpServer->getWorkerStatusInfo());
    }

    public function testAction()
    {
        $arrRet = $this->di->httpServer->dispatchTask( 'for1', 2, $this->request );

        var_dump( $arrRet );

    }

    public function notFoundAction()
    {
        echo __METHOD__, '<br>';
    }
}